package com.zzl.boot.bigevent.controller;

import com.zzl.boot.bigevent.pojo.article;
import com.zzl.boot.bigevent.pojo.result;
import com.zzl.boot.bigevent.pojo.tag;
import com.zzl.boot.bigevent.service.articleTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/artTag")
@Validated
public class articleTagController {
    @Autowired
    private articleTagService service;
    //添加文章和分类的映射
    @PostMapping("/add")
    public result addartTag(@Validated Integer articleId,@Validated Integer tagId) {
        //System.out.println(articleId+" "+tagId);
        service.addartTag(articleId,tagId);
        return result.success();
    }
    //获取文章对应的标签的列表
    @GetMapping("/list")
    public result<List<tag>> listartTag(Integer articleId) {
        List<tag> list=service.getList(articleId);
        return result.success(list);
    }
    //修改文章对应的标签
    @GetMapping("/update")
    public result updateartTag(Integer articleId, Integer tagId) {
        service.update(articleId,tagId);
        return result.success();
    }
    //删除文章对应的标签
    @DeleteMapping()
    public result deleteartTag(Integer articleId) {
        service.del(articleId);
        return result.success();
    }
    //获取标签对应的文章数量
    @GetMapping("/artilceCount")
    public result<Integer> artilceCount(Integer id) {
        return result.success(service.artilceCount(id));
    }

    //获取标签对应的文章列表
    @GetMapping("/articleList")
    public result<List<article>> articleList(Integer id) {
        List<article> list=service.getArticleList(id);
        return result.success(list);
    }

}
